﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Frame
{
    public class TabControlHelper
    {
        /// <summary>
        /// 将窗体添加到TabControl中最后一页
        /// </summary>
        /// <param name="tab">TabControl控件</param>
        /// <param name="frm">要添加的窗体</param>
        public static void AddTabPage(TabControl tab, Form frm)
        {
            tab.TabPages.Add(frm.Text);
            frm.TopLevel = false;
            frm.TopMost = false;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Parent = tab.TabPages[tab.TabPages.Count - 1];
            frm.Show();
            frm.Dock = DockStyle.Fill;
        }

        /// <summary>
        /// 将窗体添加到TabControl中
        /// </summary>
        /// <param name="index">要添加到的索引号</param>
        /// <param name="tab">TabControl控件</param>
        /// <param name="frm">要添加的窗体</param>
        public static bool AddTabPage(int index, TabControl tab, Form frm)
        {
            int count = tab.TabCount;
            if (index >= count)
                return false;
            tab.TabPages.Insert(index, frm.Text);
            frm.TopLevel = false;
            frm.TopMost = false;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Parent = tab.TabPages[index];
            frm.Show();
            frm.Dock = DockStyle.Fill;

            return true;
        }
    }
}
